<script setup>

// *=========================页面常量==========================*/
//路径导航
import {isNotEmpty, isNotNull} from "../../../util/index.js";
import {myPage} from "../../../util/request.js";
import {onMounted, reactive, ref} from "vue";
import {deleteApi, deleteBatchApi, pageApi} from "../../../util/axios.js";
import {notYet} from "../../../util/index.js";
import MyNav from "../../../components/MyNav.vue";
import MyHead from "../../../components/MyHead.vue";
import MyTable from "../../../components/MyTable.vue";
import MyPager from "../../../components/MyPager.vue";

// *=========================页面常量==========================*/
//路径导航
const navItems = [
  {icon: 'Order', label: '订单管理'},
  {icon: 'Flag', label: '购物车列表'},
];

//页面头
const headItems = [
  {type: 'ipt', span: 5, placeholder: '按账号搜索', callback: pageLikeTitle},
];

//表格列
const columns = [
  {label: '用户账号', prop: 'username', width: 120},
  {label: '课程标题', prop: 'courseTitle', width: 120},
  {label: '课程封面图', prop: 'courseCover', width: 120},
  {label: '课程单价', prop: 'coursePrice', width: 120},
];

// *=========================分页查询==========================*/
//表格行+分页+菜单标题
let records = ref();
let pageInfo = reactive({pageNum: 1, pageSize: 5, callback: page});
let username = ref();

//
async function page(pageNum = pageInfo['pageNum'],
                    pageSize = pageInfo['pageSize']) {
  let config = {
    records, pageInfo,
    api: pageApi,
    params: {pageNum, pageSize},
    args: {module: 'cart'},
  }
  if (isNotEmpty(username.value)) config['params']['username'] = username.value;
  await myPage(config);
}

// *=========================按菜单标题模糊查询==========================*/
//
function pageLikeTitle(val) {
  if (isNotNull(val) || username.value) {
    username.value = val;
    page();
  }
}

// *=========================加载函数==========================*/
onMounted(() => page());
</script>

<template v-if="records">
  <my-nav :items="navItems"/>
  <my-head :items="headItems"/>
  <my-table module="cart"
            insert-page="/CartInsert"
            update-page="/CartUpdate"
            :delete-api="deleteApi"
            :delete-batch-api="deleteBatchApi"
            :delete-callback="page"
            :excel-api="notYet"
            :records="records"
            :columns="columns"/>
  <my-pager :page-info="pageInfo"/>
</template>

<style scoped lang="scss">

</style>